<!--
 * @创建文件时间: 2020-03-04 15:02:09
 * @Auther: 猿小天
 * @最后修改人: 猿小天
 * @最后修改时间: 2020-08-29 18:31:55
 * @联系Qq:1638245306
 * @文件介绍: 
-->
<!DOCTYPE html>
<html>
    <head>
        <title>WebSocket demo</title>
    </head>
    <body>
		<div>
			<input id="sendVal" value="" />
			<button onclick="enter()">发送</button>
		</div>
        <script>
            var ws = new WebSocket("ws://127.0.0.1:8000?username=李四"),
                messages = document.createElement('ul');
            ws.onmessage = function (event) {
				console.log(event)
                var messages = document.getElementsByTagName('ul')[0],
                    message = document.createElement('li'),
                    content = document.createTextNode(event.data);
                    console.log(event.data)
                message.appendChild(content);
                messages.appendChild(message);
            };
            document.body.appendChild(messages);
			function enter(){
			var value = document.getElementById('sendVal').value
				ws.send(JSON.stringify({'content':value}))
			}
        </script>
    </body>
</html>

